package com.sc.VenusQueryBeta.presenter.home.tabs;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.home.tabs.ZhiXunContract;
import com.sc.VenusQueryBeta.model.bean.home.HomeBannerBean;
import com.sc.VenusQueryBeta.model.bean.home.HomeNoticeBean;
import com.sc.VenusQueryBeta.model.bean.home.HostListBean;
import com.sc.VenusQueryBeta.model.home.tabs.ZhiXunModel;

import io.reactivex.functions.Consumer;

/**
 * Created by SC-02 on 2018/9/19.
 *最新资讯presenter
 */

public class ZhiXunPresenter extends ZhiXunContract.ZhiXunPresenter {

    public static ZhiXunPresenter newINstance() {
        return new ZhiXunPresenter();
    }

    @Override
    protected ZhiXunContract.IZhiXunModel getModel() {
        return ZhiXunModel.newInstance();
    }

    @Override
    public void onStart() {

    }


    @Override
    public void getHomeBannerData() {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getHomeBanner().subscribe(new Consumer<HomeBannerBean>() {
            @Override
            public void accept(HomeBannerBean homeBannerBean) throws Exception {
                if (mIView != null)
                    mIView.showHomeBannerDataSuccess(homeBannerBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error.");
                    mIView.showNetworkError();
                }
            }
        }));
    }

    /**
     * 获取公告bean
     */
    @Override
    public void getHomeNoticeData() {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getHomeNotice().subscribe(new Consumer<HomeNoticeBean>() {

            @Override
            public void accept(HomeNoticeBean homeNoticeBean) throws Exception {
                if (mIView != null)
                    mIView.showHomeNoticeDataSuccess(homeNoticeBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("error="+throwable.getLocalizedMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error.");
                    mIView.showNetworkError();
                }
            }
        }));
    }

    /**
     * 获取首页活动列表
     */
    @Override
    public void getHotActivityListData() {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getHomeHotList().subscribe(new Consumer<HostListBean>() {

            @Override
            public void accept(HostListBean hostListBean) throws Exception {
                if (mIView != null)
                    mIView.showHomHotActivityListDataSuccess(hostListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("error="+throwable.getLocalizedMessage());
                if (mIView != null) {
//                    if (mIView.isVisiable())
//                        mIView.showToast("Network error.");
                    mIView.showNetworkError();
                }
            }
        }));
    }

    @Override
    public void loadLatestList() {

    }

    @Override
    public void loadMoreList() {

    }

    @Override
    public void onItemClick(int position, Object item) {

    }
}
